//
//  CSBUserDymCell.swift
//  CurSodoboAer
//
//  Created by CurSodoboAer on 2024/11/5.
//

import UIKit

class CSBUserDymCell: UICollectionViewCell {
    
    private  var csbColoter:UIColor = .brown
    var csbFplowe:CGFloat = 23.1
    var csbHeihei:UIFont?
    
    private let daDymbgCSB = UIImageView()
    private let daDymHeadCSB = UIImageView()
    
    
    private let uderNamerCSB = UILabel()
    private let uderTimeCSB = UILabel()
    
    private let uderDymDescCSB = UILabel()
   
    
    private let likrCSBButton = UIButton.init()
    private let commentCSBButton = UIButton.init()
    
    func comekwith(uhuie:Dictionary<String,String>) {
        daDymbgCSB.image = UIImage(named: uhuie["csbpersonDymPic"] ?? "")
        daDymHeadCSB.image =  UIImage(named: uhuie["csbpersonHead"] ?? "")
        uderNamerCSB.text =  uhuie["csbpersonName"] ?? ""
        uderTimeCSB.text =   uhuie["csbpersonDymTime"] ?? ""
        uderDymDescCSB.text =   uhuie["csbpersonDymTitle"] ?? ""
        
        likrCSBButton.isSelected =   (uhuie["heartForerDym"] ?? "" == "1") ? true : false
        likrCSBButton.setTitle(" " + (uhuie["csbpersonbelikecount"] ?? "0"), for: .normal)
       
        if csbColoter == UIColor.black {
            csbHeihei = UIFont.systemFont(ofSize: csbFplowe)
            self.backgroundColor = csbColoter
        }else{
            csbHeihei = UIFont.systemFont(ofSize: csbFplowe + 1)
        }
        guard csbHeihei != nil else { return  }

        if self.backgroundColor == csbColoter {
            let qurk = UIButton(configuration: UIButton.Configuration.plain())
            qurk.isHidden = true
            qurk.isEnabled = false
            addSubview(qurk)
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .clear
        daDymbgCSB.layer.cornerRadius = 28.xQQ
        daDymbgCSB.layer.masksToBounds = true
        daDymbgCSB.contentMode = .scaleAspectFill

       
        daDymHeadCSB.layer.cornerRadius = 27.xQQ
        daDymHeadCSB.layer.masksToBounds = true
        daDymHeadCSB.contentMode = .scaleAspectFill

        uderNamerCSB.textColor = .white
        uderNamerCSB.textAlignment = .center
        uderNamerCSB.font = UIFont(name: "Helvetica Bold", size: 15)
        
        
        uderTimeCSB.textColor = .white
        uderTimeCSB.textAlignment = .right
        uderTimeCSB.font = UIFont(name: "Helvetica", size: 12)
        
        uderDymDescCSB.textColor = .white

        uderDymDescCSB.font = UIFont(name: "Kailasa Regular", size: 16)
        
        likrCSBButton.setImage(UIImage.init(named: "csb_zan_un"), for: .normal)
        likrCSBButton.setImage(UIImage.init(named: "csb_zan"), for: .selected)
        likrCSBButton.setTitleColor(.white, for: .normal)
        likrCSBButton.titleLabel?.font = UIFont(name: "Kailasa Regular", size: 14)
        
        commentCSBButton.setImage(UIImage.init(named: "csb_comment"), for: .normal)
        commentCSBButton.setTitleColor(.white, for: .normal)
        commentCSBButton.titleLabel?.font = UIFont(name: "Kailasa Regular", size: 14)
        
        addAotherCSB()
    }
    
    
    private  func addAotherCSB()  {
        contentView.addSubview(daDymbgCSB)
        contentView.addSubview(daDymHeadCSB)
        contentView.addSubview(uderNamerCSB)
        contentView.addSubview(uderTimeCSB)
        contentView.addSubview(uderDymDescCSB)
        contentView.addSubview(commentCSBButton)
        contentView.addSubview(likrCSBButton)
        daDymbgCSB.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.trailing.leading.equalToSuperview()
            make.height.equalTo(220.xQQ)
        }
        
        daDymHeadCSB.snp.makeConstraints { make in
            make.width.height.equalTo(54.xQQ)
            make.bottom.equalTo(daDymbgCSB).offset(13.xQQ)
            make.leading.equalToSuperview().offset(16.xQQ)
        }
        
        uderNamerCSB.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(4)
            make.top.equalTo(daDymHeadCSB.snp.bottom).offset(8)
        }
        
        uderTimeCSB.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-8)
            make.centerY.equalTo(uderNamerCSB)
        }
        uderDymDescCSB.snp.makeConstraints { make in
            make.top.equalTo(uderNamerCSB.snp.bottom).offset(15)
            make.leading.trailing.equalToSuperview()
        }
        
        commentCSBButton.snp.makeConstraints { make in
            make.right.equalToSuperview().inset(5)
            make.height.equalTo(22)
            make.width.equalTo(65)
            make.top.equalTo(uderDymDescCSB.snp.bottom).offset(17)
        }
        likrCSBButton.snp.makeConstraints { make in
            make.right.equalTo(commentCSBButton.snp.left).offset(-26.xQQ)
            make.height.equalTo(22)
            make.width.equalTo(65)
            make.top.equalTo(uderDymDescCSB.snp.bottom).offset(17)
        }
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
